 const path = require('path');
 const Extract =  require('extract-text-webpack-plugin');
 const Clean = require('clean-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const webpack = require('webpack');

 module.exports = {
    entry:{
        index:'./src/js/index.js'
    },
    output:{
        path:path.resolve(__dirname,'./dist'),
        filename:'./js/[name].[hash].js'
    },
    module:{
        rules:[
            {
                test:/\.js$/,
                use:{
                    loader:'babel-loader',
                    options:{
                        presets:['@babel/preset-env']
                    }
                }
            },
            {
                test:/\.scss$/,
                use:Extract.extract({
                    fallback:'style-loader',
                    use:['css-loader','sass-loader']
                })
            },
            {
                test:/\.(png|jpg|svg|gif)$/,
                use:{
                    loader:'url-loader',
                    options:{
                        limit:1000,
                        name:'imgs/[name].[ext]',
                        publicPath:'/'
                    },
                }
            }
        ]
    },
    plugins:[
        new Clean('./dist'),
        new Extract({
            filename:'./css/[name].css'
        }),
        new HtmlWebpackPlugin({
            filename:'index.html',
            template:'./src/index.html'
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer:{
        port:9090,
        hot:true
    },
    resolve:{
        alias:{
            'poem$':path.resolve(__dirname,'./src/js/poem.js')
        },
        extensions:['.js','.scss']
    },
    devtool:'cheap-module-eval-source-map'
 }